package cn.stylefeng.guns.modular.robot.controller;

import cn.stylefeng.guns.core.common.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.robot.service.OrderService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Controller
@RequestMapping("/order")
public class OrderController extends BaseController {

    private static String PREFIX = "/modular/system/order/";

    @Resource
    private OrderService orderService;

    @RequestMapping("")
    public String index() {
        return PREFIX + "order.html";
    }

    @RequestMapping("/indexBatch")
    public String indexBatch() {
        return PREFIX + "listByBatch.html";
    }

    @GetMapping("/list")
    @ResponseBody
    public LayuiPageInfo list(@RequestParam(value = "customId", required = false) String customId,
                              @RequestParam(value = "groupId", required = false) String groupId,
                              @RequestParam(value = "groupName", required = false) String groupName,
                              @RequestParam(value = "limit", required = false) Long pageSize,
                              @RequestParam(value = "page", required = false) Long pageNum) {
        return orderService.list(customId,groupId,groupName, pageSize, pageNum);
    }

    @GetMapping("/listByBatch")
    @ResponseBody
    public LayuiPageInfo listByBatch(@RequestParam(value = "batchId", required = false) String batchId,
                                     @RequestParam(value = "limit", required = false) Long pageSize,
                                     @RequestParam(value = "page", required = false) Long pageNum) {
        return orderService.listByBatch(batchId, pageSize, pageNum);
    }

    @PostMapping("/summary")
    @ResponseBody
    public ResponseData summary(@RequestParam(value = "batchId", required = false) String batchId) {
        return orderService.summary(batchId);
    }
}
